package com.baidu;

public class Student {
    public String name;
    public int age;

    public static int classRoom;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    {//构造代码块初始成员变量,创建对象时优先调用
        this.name="xiaohei";

    }
    static {//只执行一次，创建多个对象时
        //静态代码块初始化静态变量,比构造代码块更优先调用
        classRoom=30;

    }
    public void print(){
        System.out.println("姓名"+this.name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
